var table1;
$(function () {
    // initTime();
    layui.use('table', function () {
        var table = layui.table;
        table1 = table.render({
            elem: '#friendTable',
            method: 'post',
            contentType: "application/json",
            url: ctx + "/friend/list",
            title: '好友查询',
            page: true,
            request: {
                pageName: 'currentPage',
                limitName: 'pageSize'
            },
            limit: 10,
            limits: [10, 15, 20, 25, 30],
            // height: 'full-120',
            cols: [
                [
                    {
                        title: '序号', align: 'center', width: 60, templet: function (obj) {
                            return obj.LAY_INDEX
                        }
                    },
                    {field: 'fname', align: 'center', width: '100', title: '好友姓名'},
                    {
                        field: 'fimgUrl',
                        align: 'center',
                        title: '好友照片',
                        width: '170',
                        templet: '<div><img src="{{d.fimgUrl}}"></div>'
                    },
                    {field: 'fphone', align: 'center', width: '150', title: '好友手机号'},
                    // {field: 'fsex', align: 'center', width: '150', title: '好友性别'},
                    // {field: 'fage', align: 'center', width: '150', title: '好友年龄'},
                    {field: 'fidCard', align: 'center', title: '好友身份证号', width: '180'},
                    {field: 'oname', align: 'center', width: '100', title: '业主姓名'},
                    {
                        field: 'oimgUrl',
                        align: 'center',
                        title: '业主照片',
                        width: '170',
                        templet: '<div><img src="{{d.oimgUrl}}"></div>'
                    },
                    {field: 'ophone', align: 'center', width: '150', title: '业主手机号'},
                    {field: 'oidCard', align: 'center', title: '业主身份证号', width: '180'},
                    {field: 'osex', align: 'center', width: '100', title: '业主性别',
                        templet: function (d) {
                            if (d.osex == 1) {
                                return '男';
                            } else if (d.osex == 2) {
                                return '女';
                            } else {
                                return '未知';
                            }
                        }},
                    {field: 'oage', align: 'center', width: '100', title: '业主年龄'},
                    {field: 'communityName', align: 'center', title: '小区', width: '180'},
                    {field: 'ldh', align: 'center', title: '楼栋号', width: '80'},
                    {field: 'mph', align: 'center', title: '门牌号', width: '80'},
                    {field: 'ownerRelation', align: 'center', width: '120', title: '与业主关系',
                        //与业主关系 0 房主 99-租客 1-配偶 2-子 3-女 4-孙子、孙女，或外孙子、外孙女 5-父母 6-祖父母或外祖父母 7-兄、弟、姐、妹 10-儿媳 8-其他亲属 9-女婿 10-儿媳
                        templet: function (d) {
                            if (d.ownerRelation == 0) {
                                return '房主';
                            } else if (d.ownerRelation == 99) {
                                return '租客';
                            } else if (d.ownerRelation == 1) {
                                return '配偶';
                            }else if (d.ownerRelation == 2) {
                                return '子';
                            }else if (d.ownerRelation == 3) {
                                return '女';
                            }else if (d.ownerRelation == 4) {
                                return '孙子、孙女，或外孙子';
                            }else if (d.ownerRelation == 5) {
                                return '父母';
                            }else if (d.ownerRelation == 6) {
                                return '祖父母或外祖父母';
                            }else if (d.ownerRelation == 7) {
                                return '兄、弟、姐、妹';
                            }else if (d.ownerRelation == 8) {
                                return '其他亲属';
                            }
                        }},
                    {field: 'friendNumber', align: 'center', width: '120', title: '业主好友个数'},

                    {field: 'createTime', align: 'center', title: '创建时间', width: '200'}
                ]
            ]
        });
    });

})


//查询
function query() {
    const condition = {
        fname: $("#friendName").val(),
        oname: $("#ownerName").val(),
        fphone: $("#fPhone").val(),
        ophone: $("#oPhone").val(),
    }
    table1.reload({
        where: {
            "condition": condition
        }
    });
}

//清空
function clean() {

    $("#friendName").val(""),
        $("#ownerName").val(""),
        $("#fPhone").val(""),
        $("#oPhone").val(""),
        query();
    form.render();
}